package com.videoweb.controller;


import com.videoweb.annotation.Anonymous;
import com.videoweb.entity.Category;
import com.videoweb.entity.vo.categoryVo;
import com.videoweb.service.ICategoryService;
import com.videoweb.utils.AjaxResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lmr
 * @since 2025-05-17
 */

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;

    @GetMapping("/getCategory")
//    @GetMapping("/info")   category/get
    public AjaxResult getCategoryList(){
        List<Category> categories = categoryService.getAllCategory();

        AjaxResult result =AjaxResult.success();

        List<categoryVo> voList = categories.stream()
                .map(category -> {
                    categoryVo vo = new categoryVo();  // 修正类名首字母大写（假设类名为CategoryVo）
                    BeanUtils.copyProperties(category, vo);
                    return vo;
                })
                .collect(Collectors.toList());
        return AjaxResult.success(voList);


//        return categories.stream()
//                .map(category -> {
//                    categoryVo vo = new categoryVo();
//                    BeanUtils.copyProperties(category, vo); // 注意顺序：目标在前
//                    return vo;
//                })
//                .collect(Collectors.toList());

    }

}
